/*
 * GraphicsManager.cpp
 *
 *  Created on: Sep 29, 2009
 *      Author: tiago.zaccaro
 */

#include "Graphics/GraphicsManager.h"

namespace AcquaEngine {

namespace Graphics {

GraphicsManager::GraphicsManager() : mRoot(0) {

}

GraphicsManager::~GraphicsManager() {

}

bool GraphicsManager::initialise() {
	mRoot = OGRE_NEW Root();

	if (!mRoot->restoreConfig()) {
		if (!mRoot->showConfigDialog()) {
			return false;
		} else {
			mRoot->saveConfig();
		}
	}

	mRenderWindows.push_back(mRoot->initialise(true, "AcquaEngine RenderWindow"));

	mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC, "AcquaEngine");

	return true;
}

void GraphicsManager::destroy() {
	if (mRoot)
		OGRE_DELETE mRoot;
}

Camera *GraphicsManager::createCamera(Ogre::String name) {
	Ogre::Camera *camera = mSceneMgr->createCamera(name);

	Camera *gCamera = new Camera(camera);

	mCameras.push_back(gCamera);

	return gCamera;
}

Viewport *GraphicsManager::createViewport(Ogre::Camera *camera, Ogre::RenderWindow *window) {
	Ogre::Viewport *viewport = window->addViewport(camera);

	Viewport *gViewport = new Viewport(window, viewport);

	return gViewport;
}

Ogre::SceneManager *GraphicsManager::getSceneManager() {
	return mSceneMgr;
}

Ogre::Root *GraphicsManager::getRoot() {
	return mRoot;
}

}

}
